package com.huaxin.common.findutils;

import android.content.Context;
import android.util.DisplayMetrics;

@SuppressWarnings("all")
public class dpxUtil {
    private static boolean deviceDataInited = false;
    private static float displayMetricsDensity;
    private static int displayMetricsWidthPixels;
    private static int displayMetricsHeightPixels;


    public static void initDeviceData(Context context) {
        DisplayMetrics displayMetrics = null;
        if (context.getResources() != null && (displayMetrics = context.getResources().getDisplayMetrics()) != null) {
            displayMetricsDensity = displayMetrics.density;
            displayMetricsWidthPixels = displayMetrics.widthPixels;
            displayMetricsHeightPixels = displayMetrics.heightPixels;
        }
        deviceDataInited = true;
    }

    public static int dip2px(Context context, float dipValue) {
        if (!deviceDataInited) {
            initDeviceData(context);
        }
        return (int) (dipValue * displayMetricsDensity + 0.5f);
    }
}
